#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Print answer (Euler problem 85) and process time

created on Sat, 26 Nov 2011

@author archpy
"""

from time import time

def resolve(params):
    """
    Resolve Euler's problem 85 
    """
    #get parameter
    value = params["value"]
    delta_min = value
    res = None
    verti_length = 1
    hori_length = 1
    coeff = [1]
    while hori_length != 0:
        verti_length += 1
        coeff.append(coeff[-1] + verti_length)
        line = []
        for i in range(verti_length):
            actual_value = coeff[-1] * coeff[i]
            delta = actual_value - value
            if abs(delta) < delta_min:
                delta_min, res = abs(delta), (i+1)*verti_length
            elif delta > 0:
                continue
            line.append(actual_value)
        hori_length = len(line)
    return res
    
if __name__ == "__main__":
    PARAMS = {}
    #put parameters
    PARAMS["value"] = 2 * 10**6
    TIME_BEGIN = time()
    RES = resolve(PARAMS)
    TIME_END = time()-TIME_BEGIN
    print("Problem 0085:")
    print("------------")
    print("Answer : %d" %RES)
    print("Time : %f\"" %TIME_END)
